#include "sessionfriendarea.h"

#include "sessionfriendarea.h"

#include <QScrollBar>
#include <QVBoxLayout>
#include <QPushButton>
#include <QLabel>
#include <QStyleOption>
#include <QPainter>

SessionFriendArea::SessionFriendArea(QWidget *parent)
    : QScrollArea{parent}
{
    // 1. 设置必要的属性
    // 设置了这个属性, 才能够开启滚动效果
    this->setWidgetResizable(true);
    // 设置滚动条相关的样式
    this->verticalScrollBar()->setStyleSheet("QScrollBar:vertical { width: 2px; background-color: rgb(46, 46, 46);}");
    this->horizontalScrollBar()->setStyleSheet("QScrollBar:horizontal { height: 0px; }");
    this->setStyleSheet("QWidget { border: none;}");

    // 2. 把 widget 创建出来
    container = new QWidget();
    container->setFixedWidth(310);
    this->setWidget(container);

    // 3. 给这个 widget 指定布局管理器, 以便后续添加元素进去
    QVBoxLayout* layout = new QVBoxLayout();
    layout->setContentsMargins(0, 0, 0, 0);
    layout->setSpacing(0);
    layout->setAlignment(Qt::AlignTop);
    container->setLayout(layout);

//简单测试一下滚动的效果, 先去掉, 后续添加 Item
    for (int i = 0; i < 50; ++i) {
        QPushButton* btn = new QPushButton();
        //btn->setStyleSheet("border: 1px solid black;");

        btn->setStyleSheet("border: 2px solid #8f8f91;"
                             "border-radius: 6px;"
                             "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
                             "                              stop: 0 #f6f7fa, stop: 1 #dadbde);");
        btn->setText("按钮");
        layout->addWidget(btn);
    }

// 构造出一些临时数据, 用来作为 "界面调试" 依据. 后续要删除掉
// #if TEST_UI
//     QIcon icon(":/resource/image/defaultAvatar.png");
//     for (int i = 0; i < 30; ++i) {
//         this->addItem(SessionItemType, QString::number(i), icon, "张三" + QString::number(i), "最后一条消息" + QString::number(i));
//     }
// #endif
}
